class Student{
    public int count ;
    public synchronized void add(){
        count ++ ;
    }
    public void add2(){
        synchronized(this){
            count++ ;
        }
    }
   synchronized public  static  void add3(){

    }
    public  static  void add4(){
         synchronized(Student.class){

         }
    }

}




public class Test1 {
    public static void main(String[] args) throws InterruptedException {
         Object o1 = new Object() ;
         Object o2 = new Object() ;
        Thread t1 = new Thread(()-> {
            synchronized(o1){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (o2){
                    System.out.println("t1");
                }
            }

         },"t1");
        Thread t2 = new Thread(()-> {
            synchronized(o1){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (o2){
                    System.out.println("t2");
                }
            }

        },"t2");
         t1.start();
         t2.start();
         t1.join();
         t2.join();
        System.out.println("结束");
    }
}
